define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods/apply/index' + location.search,
                    add_url: 'goods/apply/add',
                    edit_url: 'goods/apply/edit',
                    del_url: 'goods/apply/del',
                    multi_url: 'goods/apply/multi',
                    import_url: 'goods/apply/import',
                    table: 'apply_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',

                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'apply_user', title: __('Apply_user'), operate: 'LIKE' },
                        { field: 'name', title: __('Name'), operate: 'LIKE' },
                        { field: 'spec', title: __('Spec') },
                        { field: 'tags', title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag },
                        { field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images },
                        { field: 'trademark', title: __('Trademark'), operate: 'LIKE' },
                        { field: 'msg', title: __('Msg'), operate: 'LIKE' },
                        { field: 'status', title: __('Status'), searchList: { "0": __('Status 0'), "1": __('Status 1'), "2": __('Status 2') }, formatter: Table.api.formatter.status },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'acct_id', title: __('授权平台'), operate: 'LIKE', searchList: Config.adminList, formatter: Table.api.formatter.flag },
                        { field: 'store', title: __('Store'), operate: 'LIKE' },
                        { field: 'demand', title: __('Demand'), operate: 'LIKE' },
                        { field: 'content', title: __('Content'), operate: 'LIKE' },
                        { field: 'price', title: __('Price'), operate: 'BETWEEN' },
                        { field: 'mobile', title: __('Mobile'), operate: 'LIKE' },
                        { field: 'type', title: __('是否寄送样品'), searchList: { "0": __('否'), "1": __('是') }, formatter: Table.api.formatter.normal },
                        { field: 'is_back', title: __('是否寄回样品'), searchList: { "0": __('否'), "1": __('是') }, formatter: Table.api.formatter.normal },
                        { field: 'back_name', title: __('寄回人'), operate: 'LIKE'  },
                        { field: 'back_mobile', title: __('寄回电话'), operate: 'LIKE'  },
                        { field: 'back_address', title: __('寄回地址'), operate: 'LIKE'  },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'process',
                                    title: '进程',
                                    text: '进程',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    extend: 'data-area=["80%","80%"]',
                                    url: 'goods/applyinfo/index',//接口地址 控制器名/方法名
                                    visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if (Config.acct_visible) {
                                            return true;//显示
                                        } else {
                                            return false;//显示
                                        }

                                    },
                                },
                                {
                                    name: 'edit',
                                    title: '编辑',
                                    text: '编辑',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'goods/apply/edit',//接口地址 控制器名/方法名
                                    visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if (Config.acct_visible) {
                                            return false;//显示
                                        } else {
                                            return true;//显示
                                        }

                                    },
                                },
                                {
                                    name: 'del',
                                    title: '删除',
                                    text: '删除',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'goods/apply/del',//接口地址 控制器名/方法名
                                    visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if (Config.acct_visible) {
                                            return false;//显示
                                        } else {
                                            return true;//显示
                                        }

                                    },
                                },
                            ]
                        }
                    ]
                ]
            });
            // visible: Config.acct_visible ? false : true,
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
